package busuanzi.util;

import com.alibaba.fastjson.JSON;
import sardine.ResponseTransformer;

import java.util.LinkedList;
import java.util.List;

/**
 * Auth: bruce-sha
 * Date: 2015/4/29
 */
public abstract class Sugars {
    public static final String VOID = "";
    public static final String OK = "success";

    public static final ResponseTransformer SimpleJsonTransformer = new ResponseTransformer() {
        public String render(Object model) throws Exception {
//            return JSON.toJSONString(model);
//            return JSON.toJSONStringWithDateFormat(model, "yyyy-MM-dd HH:mm:ss.SSS");
            return JSON.toJSONStringWithDateFormat(model, "yyyy-MM-dd HH:mm:ss");
        }
    };

    public static final ResponseTransformer HtmlJsonTransformer = new ResponseTransformer() {
        public String render(Object o) throws Exception {
            return JSON.toJSONString(o, true).replaceAll("\n", "<br>").replaceAll("\t", "&nbsp;&nbsp;");
        }
    };

    public static void main(String[] args) {
        List<String> lst = new LinkedList<>();
        lst.add("2015:1");
        lst.add("2015:2");
        lst.add("2015:3");
        System.out.println(JSON.toJSONString(lst, true));

    }
}
